﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.IO;
using System.Windows.Forms;

namespace ThreadEyePro
{
    public partial class FormOptions : Form
    {
        public string optBrowser = "Built-in Browser";
        public bool optSound = false;
        public int optTimer = 1;
        public string optSoundFile = string.Empty;
        public bool optEnablePM = false;
        public string kaskusUsername = string.Empty;
        public string kaskusPassword = string.Empty;

        public FormOptions()
        {
            InitializeComponent();
            checkBoxSound.CheckedChanged += new EventHandler(checkBoxSound_CheckedChanged);
            checkBoxPm.CheckedChanged += new EventHandler(checkBoxPm_CheckedChanged);
        }

        void checkBoxPm_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBoxPm.Checked == false)
            {
                textBoxUsername.Text = string.Empty;
                maskedTextBoxPassword.Text = string.Empty;
                textBoxUsername.Enabled = false;
                maskedTextBoxPassword.Enabled = false;
            }
            else
            {
                textBoxUsername.Enabled = true;
                maskedTextBoxPassword.Enabled = true;
            }
        }

        void checkBoxSound_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBoxSound.Checked == true)
            {
                OpenFileDialog fDialog = new OpenFileDialog();
                fDialog.Title = "Open WAV sound file";
                fDialog.Filter = "WAV File|*.wav";
                fDialog.Multiselect = false;
                if (fDialog.ShowDialog() == DialogResult.OK)
                {
                    string file = fDialog.FileName.ToString();
                    if (File.Exists(file))
                    {
                        optSoundFile = file;
                    }
                }
                else
                {
                    optSoundFile = string.Empty;
                    checkBoxSound.Checked = false;
                }
            }
            else
            {
                optSoundFile = string.Empty;
            }
        }

        private void FormOptions_Load(object sender, EventArgs e)
        {
            if (comboBoxBrowser.Items.Count < 1)
            {
                comboBoxBrowser.Items.Add("Built-in Browser");
                comboBoxBrowser.Items.Add("System Default");
                if (File.Exists(@"C:\Program Files\Mozilla Firefox\firefox.exe"))
                {
                    comboBoxBrowser.Items.Add("Mozilla Firefox");
                }
            }
            comboBoxBrowser.SelectedItem = optBrowser;
            numericUpDownTimer.Value = optTimer;
            if (optSoundFile != string.Empty && File.Exists(optSoundFile))
            {
                checkBoxSound.Checked = optSound;
            }
            textBoxUsername.Text = kaskusUsername;
            maskedTextBoxPassword.Text = kaskusPassword;
            checkBoxPm.Checked = optEnablePM;

            if (optEnablePM == false)
            {
                textBoxUsername.Enabled = false;
                maskedTextBoxPassword.Enabled = false;
            }
        }

        private void buttonOk_Click(object sender, EventArgs e)
        {
            this.optBrowser = comboBoxBrowser.SelectedItem.ToString();
            this.optSound = checkBoxSound.Checked;
            this.optTimer = Convert.ToInt16(numericUpDownTimer.Value.ToString());
            this.kaskusUsername = textBoxUsername.Text;
            this.kaskusPassword = maskedTextBoxPassword.Text;
            this.optEnablePM = checkBoxPm.Checked;

            DialogResult = DialogResult.OK;
        }
    }
}
